package com.magesti.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.magesti.DAO.DaoFactory;
import com.magesti.DAOinterface.OperationInterfaceDAO;
import com.magesti.beans.Operation;
import com.magesti.exception.DAOException;
import com.magesti.ressource.Global;
import com.magesti.ressource.ServletGlobal;

@SuppressWarnings("serial")
public class AfficheBudget extends HttpServlet {
	private OperationInterfaceDAO operationDAO;
	public void init() throws ServletException {
		
		DaoFactory f = ((DaoFactory) getServletContext().getAttribute(
				Global.ATT_CONTEXT_DAO_FACTORY));
		operationDAO = f.getOperationDAO();
	}

	//TODO: modifier ces variables
	// String navNomPage =Global.FORM_NAV_NOM_EXEMPLE;
	// String navDescriptionPage = Global.FORM_NAV_DESCRIPTION_EXEMPLE;		

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		 //request.setAttribute(Global.ATT_REQUEST_NOM_PAGE,navNomPage);
		 //request.setAttribute(Global.ATT_REQUEST_DESCRIPTION_PAGE,navDescriptionPage);
		int id_op=Global.VALEUR_ID_DEFAUT;
		Operation op = null;
		String erreur = "";
		
		try {
			id_op = ServletGlobal.checkIdOperation(request);
			op = operationDAO.createOperation(id_op);

		} catch (DAOException e) {
			erreur = e.getMessage();
		}
		
		request.setAttribute(Global.ATT_REQUEST_OPERATION,op);
		request.setAttribute(Global.ATT_REQUEST_ERREUR,erreur);
	
		 this.getServletContext().getRequestDispatcher(Global.VUE_JSP_AFFICHE_BUDGET).forward(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		 //request.setAttribute(Global.ATT_REQUEST_NOM_EXEMPLE,navNomPage);
		 //request.setAttribute(Global.ATT_REQUEST_DESCRIPTION_EXEMPLE,navDescriptionPage);
		
		
		
		// this.getServletContext().getRequestDispatcher(Global.VUE_EXEMPLE).forward(request,response);
	}

}
